package robocup.component.actionfactories;

import robocup.component.WorldModel;
import robocup.component.actions.Action;
import robocup.component.actions.PointToAction;
import robocup.component.geometry.Vektor;
import robocup.component.worldobjects.Player;
import robocup.component.worldobjects.Player.RELATIVE;

/**
 * A factory for creating pointTo actions.
 */
public class PointToActionFactory {

  /**
   * Vektor object for calculating the target to point at!
   */
  public static final Vektor pointVektor = new Vektor();

  /**
   * a dummy-object
   */
  public static final Player selfDummy   = Player.getDummyInstance();

  /**
   * This method calculates a pointToAction to an absolute target, whereas the
   * point of view is the player.
   * 
   * @param world -
   *          the current world-model
   * @param pointTo -
   *          the target vektor
   * @param mainAction
   *          the main action
   * @return the pointTo Action, targeting from <self> to <pointTo>
   */
  public static PointToAction pointToPoisitionAction(final WorldModel world,
      final Vektor pointTo,
      final Action mainAction) {

    PointToActionFactory.selfDummy.copy(world.getSelfRef());
    PointToActionFactory.selfDummy.predictThisAfterAction(mainAction);
    final double angleTo = PointToActionFactory.selfDummy.getAngleRel(pointTo,
        RELATIVE.TO_HEAD);
    final double distTo = PointToActionFactory.selfDummy.getDistance(pointTo);

    return new PointToAction(distTo, angleTo);
  }

}
